<?php
/**
 * Created by PhpStorm.
 * User: Mak
 * Date: 2016/1/7
 * Time: 0:15
 */

namespace Home\Controller;
use Think\Controller;
use Think\Upload;

class HomeWorkController extends Controller{

    public function _initialize(){
        header("content-type:text/html; charset=utf-8");
        $flag = session('?dataInfo');
        if(!$flag){
            $this->error("非法登录",U('Home/Index/index'));
        }

    }

    public function homework(){
        $this->assign("title","提交作业");
        $zy=M("zy");
        $data=$zy->order("time")->select();
        $this->assign("data",$data);
        $this->display();
    }

    public function add(){
        $file=$_FILES['jsjFile'];
        $config = array(
            'maxSize'      => 0, //上传的文件大小限制 (0-不做限制)
            'exts'         => array(), //允许上传的文件后缀
            'subName'      => array('date', 'Y-m-d'), //子目录创建方式，[0]-函数名，[1]-参数，多个参数使用数组
            'rootPath'     => './Public/', //保存根路径
            'savePath'     => 'Uploads/', //保存路径
            'replace'      => false, //存在同名是否覆盖
            'driver'       => 'Sae', // 文件上传驱动
        );
        $upload=new Upload($config);
        $info=$upload->uploadOne($file);
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
//            dump($file);
        }else{// 上传成功 获取上传文件信息
            $model=M("zy");
            $info["time"]=date("Y-m-d h:i:sa");
            $model->add($info);
            $this->success('上传成功！', U('Home/HomeWork/homework'));
        }
    }


}